function debounce(fn, time) {
    let timer = null
    return function () {
        // 已经点击过了,还没执行
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn()
            // fn.call(this, ...arguments)
        }, time)

    }
}

window.addEventListener('scroll', debounce(fn, 500))

function fn() {
    console.log("抖一下", ...arguments)
}

function throttle(fn, time) {
    let timer = null
    console.log('调用了')
    return function () {
        if (timer) return
        timer = setTimeout(() => {
            // fn.call(this, ...arguments)
            fn()
            clearTimeout(timer)
            timer = null
        }, time);
    }
}

window.addEventListener('scroll', throttle(fn, 1000))
